//
//  myResumeCellMerit.swift
//  LeDian
//
//  Created by 三秒文化 on 16/3/18.
//  Copyright © 2016年 51ledian. All rights reserved.
//

import UIKit
import Neon

class myResumeCellMerit: LDBaseRecFinderCell {
    
    
    var myLight:UILabel?
    var myDesc:UILabel?
    
    var backMeritImgView:UIImageView?
    var divideline:UIView?
    
    let SameLabTag = 333
    
    var model = myResumeCellMeritModel() {
        
        didSet{
            updateFrame()
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style , reuseIdentifier: reuseIdentifier)
        setDefalutContent()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func updateFrame() {
        
        setupFrame()
    }
    
    func setDefalutContent() {
        
        self.frame = LDFrame.ScreenBounds
        myLight = UILabel.setHeadTitleLab("我的亮点")
        
        divideline = UIView()//UIImageView.setupDivideLine_H(LDFrame.ScreenWidth - Margin_V * 10)
        divideline?.backgroundColor = LDLineColorLightGray
        myDesc = UILabel.setDetailsLab("", fontSize: 14, titleColor: LDFontColor.DeepGray,Alignment: nil)
        
        gapView.addSubview(myLight!)
        gapView.addSubview(divideline!)
        gapView.addSubview(myDesc!)
        
        
        /**
         生成labs
         */
        UILabel.setMoreSameLabs(self, SameLabTag: SameLabTag) { () -> Int in
            return 6
        }
        
        //UI更改修改移除
        backMeritImgView = UIImageView.setDefaultGoundImg("green_dot", radius: 5)
        addSubview(backMeritImgView!)
        
        //neon简单布局
        //左边竖线
        let VHeading = UIView()
        VHeading.backgroundColor = LDGolbalColor.GreenAssist
        gapView.addSubview(VHeading)
        
        myLight!.anchorInCorner(.TopLeft, xPad: Margin_V*3, yPad: Margin_V*4, width: 200, height: 20)
//        myLight?.align(.ToTheRightCentered, relativeTo: VHeading, padding: Margin_V*2, width: 120, height: 25)
//        backMeritImgView!.align(.UnderMatchingLeft, relativeTo: myLight!, padding: Margin_V*2, width: 15, height: 15)
//        divideline!.align(.UnderMatchingLeft, relativeTo: VHeading, padding: LDMargin_V*3, width: LDFrame.ScreenWidth - Margin_V * 10, height: 1)
        
    }
    //得到models后刷新lab内容
    func setupFrame(){
        
        backMeritImgView!.snp_makeConstraints { (make) in
            
            make.top.equalTo(myLight!.snp_bottom).offset(LDMargin_V*2)
            make.left.equalTo(myLight!.snp_left)
            make.size.equalTo(CGSizeMake(10, 10))
        }
        divideline?.snp_makeConstraints(closure: { (make) in
            
            make.top.equalTo(backMeritImgView!.snp_bottom)
            make.centerX.equalTo(backMeritImgView!)
            make.bottom.equalTo(-2)
            make.width.equalTo(0.5)
        })
        myDesc!.snp_makeConstraints { (make) in
            
            make.top.equalTo(myLight!.snp_bottom).offset(LDMargin_V*2)
            make.left.equalTo(backMeritImgView!.snp_right).offset(Margin_V*3)
            make.right.equalTo(-LDMargin_V*2)
            
        }
        
        if model.mystrengthstext.characters.count > 0 {
            
            myDesc?.attributedText = String.getAttrFormString(lineH: 10, text: model.mystrengthstext, font: LDFont.Font13)
        } else {
            
            myDesc?.text = "我的优势文本还未录入"//model.mystrengthstext
        }
        
        
        let Y = model.cellheight_desc + LDMargin_V*3 + CGRectGetMaxY(myLight!.frame)
        
        var labstitleArr = [String]()
        
        for item in model.highlights{
            
            let str = item["tag"] as? String ?? LDNull
            labstitleArr.append(str)
        }
        
        
        UILabel.setupLabFrame(labstitleArr, SameLabTag: SameLabTag, textSize: CGSizeMake(200, 15), font: LDFont.Font11, target: self, labMargin: (Origin_X: Margin_V*8, Origin_Y: Y, Margin_X: Margin_V*2, Margin_Y: Margin_V*2, LabH: 18))
        
        for i in 0..<model.highlights.count {
            
            let views = viewWithTag(SameLabTag+i) as! UILabel
            views.layer.borderColor = LDIconColor.LightGray.CGColor
            views.textColor = LDFontColor.DeepGray
        }
        
    }
    
    override func setSelected(selected: Bool, animated: Bool) {
        
        super.setSelected(selected, animated: animated)
    }
    
}
class myResumeCellMeritModel: NSObject {
    
    var height:CGFloat = LDCellFrame.Margin_V*2 + LDMargin_V*3*4 + LDMargin_V*4 //
    
    var cellheight_desc:CGFloat = 0 {
        didSet{
            height = height + cellheight_desc
        }
    }
    var cellheight_labs:CGFloat = 0 {
        didSet{
            height = height + cellheight_labs
        }
    }
    
    
    var mystrengthstext = "" {      // 我的优势文本
        didSet{
            
            let size = CGSizeMake(LDFrame.ScreenWidth - LDMargin_V * 8, CGFloat.max)
            
            let height = String.getHeightFormAttr(10, title: mystrengthstext, size: size, font: LDFont.Font13)
            cellheight_desc = height
        }
    }
    var highlightscount = "" {      // 我的亮点标签数目
        didSet{

            cellheight_labs = UILabel.getCellSampleLableH(Int(highlightscount)!, labH: LDFrame.sampleLabsInCellH, LabMargin_V: LDMargin_V)
        }
    }
    var highlights = [AnyObject]()        // 我的亮点标签数组
}
